package org.jivesoftware.smackx.filetransfer;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Callable;
import org.jivesoftware.smack.XMPPException;

public class IncomingFileTransfer extends FileTransfer
{
  private InputStream inputStream;
  private FileTransferRequest recieveRequest;

  protected IncomingFileTransfer(FileTransferRequest paramFileTransferRequest, FileTransferNegotiator paramFileTransferNegotiator)
  {
    super(paramFileTransferRequest.getRequestor(), paramFileTransferRequest.getStreamID(), paramFileTransferNegotiator);
    this.recieveRequest = paramFileTransferRequest;
  }

  private void handleXMPPException(XMPPException paramXMPPException)
  {
    setStatus(FileTransfer.Status.error);
    setException(paramXMPPException);
  }

  // ERROR //
  private InputStream negotiateStream()
    throws XMPPException
  {
    // Byte code:
    //   0: aload_0
    //   1: getstatic 72	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:negotiating_transfer	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   4: invokevirtual 59	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
    //   7: aload_0
    //   8: getfield 76	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:negotiator	Lorg/jivesoftware/smackx/filetransfer/FileTransferNegotiator;
    //   11: aload_0
    //   12: getfield 28	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:recieveRequest	Lorg/jivesoftware/smackx/filetransfer/FileTransferRequest;
    //   15: invokevirtual 82	org/jivesoftware/smackx/filetransfer/FileTransferNegotiator:selectStreamNegotiator	(Lorg/jivesoftware/smackx/filetransfer/FileTransferRequest;)Lorg/jivesoftware/smackx/filetransfer/StreamNegotiator;
    //   18: astore_1
    //   19: aload_0
    //   20: getstatic 85	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:negotiating_stream	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   23: invokevirtual 59	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
    //   26: new 87	java/util/concurrent/FutureTask
    //   29: dup
    //   30: new 8	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$2
    //   33: dup
    //   34: aload_0
    //   35: aload_1
    //   36: invokespecial 90	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$2:<init>	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;Lorg/jivesoftware/smackx/filetransfer/StreamNegotiator;)V
    //   39: invokespecial 93	java/util/concurrent/FutureTask:<init>	(Ljava/util/concurrent/Callable;)V
    //   42: astore_2
    //   43: aload_2
    //   44: invokevirtual 97	java/util/concurrent/FutureTask:run	()V
    //   47: aload_2
    //   48: ldc2_w 98
    //   51: getstatic 105	java/util/concurrent/TimeUnit:SECONDS	Ljava/util/concurrent/TimeUnit;
    //   54: invokevirtual 109	java/util/concurrent/FutureTask:get	(JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;
    //   57: checkcast 111	java/io/InputStream
    //   60: astore 8
    //   62: aload_2
    //   63: iconst_1
    //   64: invokevirtual 115	java/util/concurrent/FutureTask:cancel	(Z)Z
    //   67: pop
    //   68: aload_0
    //   69: getstatic 118	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:negotiated	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
    //   72: invokevirtual 59	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
    //   75: aload 8
    //   77: areturn
    //   78: astore 7
    //   80: new 32	XMPPException
    //   83: dup
    //   84: ldc 120
    //   86: aload 7
    //   88: invokespecial 123	XMPPException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   91: athrow
    //   92: astore 4
    //   94: aload_2
    //   95: iconst_1
    //   96: invokevirtual 115	java/util/concurrent/FutureTask:cancel	(Z)Z
    //   99: pop
    //   100: aload 4
    //   102: athrow
    //   103: astore 6
    //   105: new 32	XMPPException
    //   108: dup
    //   109: ldc 125
    //   111: aload 6
    //   113: invokespecial 123	XMPPException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   116: athrow
    //   117: astore_3
    //   118: new 32	XMPPException
    //   121: dup
    //   122: ldc 127
    //   124: aload_3
    //   125: invokespecial 123	XMPPException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   128: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   47	62	78	java/lang/InterruptedException
    //   47	62	92	finally
    //   80	92	92	finally
    //   105	129	92	finally
    //   47	62	103	java/util/concurrent/ExecutionException
    //   47	62	117	java/util/concurrent/TimeoutException
  }

  public void cancel()
  {
    setStatus(FileTransfer.Status.cancelled);
  }

  public InputStream recieveFile()
    throws XMPPException
  {
    if (this.inputStream != null)
      throw new IllegalStateException("Transfer already negotiated!");
    try
    {
      this.inputStream = negotiateStream();
      return this.inputStream;
    }
    catch (XMPPException localXMPPException)
    {
      setException(localXMPPException);
      throw localXMPPException;
    }
  }

  public void recieveFile(File paramFile)
    throws XMPPException
  {
    if (paramFile != null)
    {
      if (!(paramFile.exists()));
      try
      {
        paramFile.createNewFile();
        if (paramFile.canWrite())
          break label55;
        throw new IllegalArgumentException("Cannot write to provided file");
      }
      catch (IOException localIOException)
      {
        throw new XMPPException("Could not create file to write too", localIOException);
      }
    }
    throw new IllegalArgumentException("File cannot be null");
    label55: new Thread(new Runnable(this, paramFile)
    {
      // ERROR //
      public void run()
      {
        // Byte code:
        //   0: aload_0
        //   1: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   4: aload_0
        //   5: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   8: invokestatic 35	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:access$0	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;)Ljava/io/InputStream;
        //   11: invokestatic 39	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:access$1	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;Ljava/io/InputStream;)V
        //   14: aconst_null
        //   15: astore_2
        //   16: new 41	java/io/FileOutputStream
        //   19: dup
        //   20: aload_0
        //   21: getfield 21	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:val$file	Ljava/io/File;
        //   24: invokespecial 43	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
        //   27: astore_3
        //   28: aload_0
        //   29: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   32: getstatic 49	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:in_progress	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
        //   35: invokevirtual 53	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
        //   38: aload_0
        //   39: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   42: aload_0
        //   43: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   46: invokestatic 56	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:access$3	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;)Ljava/io/InputStream;
        //   49: aload_3
        //   50: invokevirtual 60	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:writeToStream	(Ljava/io/InputStream;Ljava/io/OutputStream;)V
        //   53: aload_3
        //   54: astore_2
        //   55: aload_0
        //   56: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   59: invokevirtual 64	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:getStatus	()Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
        //   62: getstatic 49	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:in_progress	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
        //   65: invokevirtual 68	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:equals	(Ljava/lang/Object;)Z
        //   68: ifeq +13 -> 81
        //   71: aload_0
        //   72: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   75: getstatic 71	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:complete	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
        //   78: invokevirtual 53	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
        //   81: aload_0
        //   82: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   85: invokestatic 56	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:access$3	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;)Ljava/io/InputStream;
        //   88: ifnull +13 -> 101
        //   91: aload_0
        //   92: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   95: invokestatic 56	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:access$3	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;)Ljava/io/InputStream;
        //   98: invokevirtual 76	java/io/InputStream:close	()V
        //   101: aload_2
        //   102: ifnull +7 -> 109
        //   105: aload_2
        //   106: invokevirtual 79	java/io/OutputStream:close	()V
        //   109: return
        //   110: astore_1
        //   111: aload_0
        //   112: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   115: aload_1
        //   116: invokestatic 83	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:access$2	(Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;Lorg/jivesoftware/smack/XMPPException;)V
        //   119: goto -10 -> 109
        //   122: astore 11
        //   124: aload 11
        //   126: astore 5
        //   128: aload_0
        //   129: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   132: getstatic 86	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:error	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
        //   135: invokevirtual 53	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
        //   138: aload_0
        //   139: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   142: getstatic 92	org/jivesoftware/smackx/filetransfer/FileTransfer$Error:stream	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;
        //   145: invokevirtual 96	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setError	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;)V
        //   148: aload_0
        //   149: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   152: aload 5
        //   154: invokevirtual 100	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setException	(Ljava/lang/Exception;)V
        //   157: goto -102 -> 55
        //   160: astore 10
        //   162: aload 10
        //   164: astore 9
        //   166: aload_0
        //   167: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   170: getstatic 86	org/jivesoftware/smackx/filetransfer/FileTransfer$Status:error	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;
        //   173: invokevirtual 53	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setStatus	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Status;)V
        //   176: aload_0
        //   177: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   180: getstatic 103	org/jivesoftware/smackx/filetransfer/FileTransfer$Error:bad_file	Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;
        //   183: invokevirtual 96	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setError	(Lorg/jivesoftware/smackx/filetransfer/FileTransfer$Error;)V
        //   186: aload_0
        //   187: getfield 19	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer$1:this$0	Lorg/jivesoftware/smackx/filetransfer/IncomingFileTransfer;
        //   190: aload 9
        //   192: invokevirtual 100	org/jivesoftware/smackx/filetransfer/IncomingFileTransfer:setException	(Ljava/lang/Exception;)V
        //   195: goto -140 -> 55
        //   198: astore 6
        //   200: goto -91 -> 109
        //   203: astore 7
        //   205: goto -104 -> 101
        //   208: astore 8
        //   210: aload 8
        //   212: astore 9
        //   214: aload_3
        //   215: astore_2
        //   216: goto -50 -> 166
        //   219: astore 4
        //   221: aload 4
        //   223: astore 5
        //   225: aload_3
        //   226: astore_2
        //   227: goto -99 -> 128
        //
        // Exception table:
        //   from	to	target	type
        //   0	14	110	org/jivesoftware/smack/XMPPException
        //   16	28	122	org/jivesoftware/smack/XMPPException
        //   16	28	160	java/io/FileNotFoundException
        //   105	109	198	java/lang/Throwable
        //   91	101	203	java/lang/Throwable
        //   28	53	208	java/io/FileNotFoundException
        //   28	53	219	org/jivesoftware/smack/XMPPException
      }
    }
    , "File Transfer " + this.streamID).start();
  }
}